//
//  ResultInfo.swift
//  wanjia
//
//  Created by Stan Hu on 31/10/2016.
//  Copyright © 2016 Stan Hu. All rights reserved.
//

import Foundation

class ResultInfo:NSObject {
    
    var resultCode:Int = -1
    var resultMessage:String = "无法连接网络，请重新再试"
    var resultContent: Any?
    var requestId = ""
    /// json字符串
    var resultStr = ""
    
    static func convertPHPResponseNorToResultInfo(response:Any?) -> ResultInfo {
        let result = ResultInfo()
        if response == nil {
            return result
        }
//        let err: NSErrorPointer = nil
        if response is Data {
            let strRs = String(data: response as! Data, encoding: String.Encoding.utf8)
            result.resultStr = strRs ?? ""
        }

  
        guard let anyObject = try? JSONSerialization.jsonObject(with: response! as! Data, options: .mutableContainers) else {
            result.resultMessage = "非法的JSON"
            return result
        }
        
        
//        let json = JSON(anyObject)
        
//        let code = json["status"].object
//        result.resultCode = Tool.toInt(code)
//
//        result.resultMessage = json["message"].string ?? "无法连接网络，请重新再试"
        result.resultContent = anyObject
        

        return result
    }
    
}
